package comp353Games;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Deanna
 */

//imported packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Controller implements MouseListener{
    
//instance variables
    
    /**
     * Current Player.
     */
    private int currentPlayer;

    /**
     * Current Player.
     */
    private JLabel errorLabel;

    /**
     * The underlying game.
     */
    private Game game;

    /**
     * The Frame containing the display of the Snort game
     */
    private JFrame frame;

    /**
     * A Label showing the current player's turn
     */
    private JLabel statusBar;

    /**
     * The display of the game
     */
    private Display GUI;    


    //constants

    /**
     * Number of players
     */
    public static final int NUM_PLAYERS = 2;


    //public methods

    /**
     * Class constructor for generic game.
     * 
     * @param game  Snort game to begin with.
     */
    public void Controller(){
       
    }
    
    /**
     * Public Constructor for the game.
     */
    public Controller(Game game) {
        this.game = game;
        this.currentPlayer = 1;
        if (game.hasMovesLeft(this.currentPlayer)){
            System.out.println("It's Player "+ currentPlayer+"'s turn...");
        }
        this.GUI = new Display(this.game);
        this.GUI.setVisible(true);
        
    }
   
    /**
     * Creates a display for the game.
     */
    public void displayGame() {
        this.frame.setContentPane(new Display(this.game));
        this.frame.getContentPane().add(statusBar,BorderLayout.NORTH);
        this.frame.getContentPane().add(errorLabel,BorderLayout.SOUTH);
        this.frame.pack();
        this.frame.repaint();
    }
        
  
    /**
     * Moves to a new game
     *
     * @param game  New game to make a move to.
     */
    public void move(Game game) {
        this.game = game;
        this.currentPlayer++;
        if (this.currentPlayer > NUM_PLAYERS) {
            currentPlayer = 1;
        }
        
        if (game.hasMovesLeft(this.currentPlayer)){
            statusBar.setText("It's Player "+ currentPlayer+"'s turn...");
        }
        this.displayGame();
    }

    
    
    /**
     * Sets the text for the error message
     * 
     * @param status    The error message that errorLabel is being set to
     */
    public void setError(String status){
        errorLabel.setText(status);
    }
    
    /**
     * Returns a string version of this.
     *
     * @param indent  Indentation string.
     * @return      An empty string.
     */
    public String toString(String indent){
        String string = "";
        return string;
    }
  
    
    /**
     * Returns a string version of this.
     * 
     * @return      An empty string.
     */
    @Override
    public String toString() {
        return this.toString("");
    }
  
    @Override
    public void mouseClicked (java.awt.event.MouseEvent evt) {
        
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
    
   
   
} 



int index = 0;
String gameType = "";
while (fileString.charAt(index) != "<")&& (index < 10){
index ++;
}
if (index != 10){
index ++;
while (fileString.charAt(index) != ">"{
gameType += fileString.charAt(index);
index ++;
}
index++;

}
if gameType == "Clobber"{
GameModel loadHelper = new Clobber();
GameModel game = loadHelper.load(fileString, index);
}
if gameType == "Snort"{
GameModel loadHelper = new SnortCol(true);
GameModel game = loadHelper.load(fileString, index);
}
if gameType == "Col"{
GameModel loadHelper = new SnortCol(false);
GameModel game = loadHelper.load(fileString, index);
}
if gameType == "Nim"{
GameModel loadHelper = new Nim();
GameModel game = loadHelper.load(fileString, index);
}
if gameType == "ToadsAndFrogs"{
GameModel loadHelper = new ToadsAndFrogs();
GameModel game = loadHelper.load(fileString, index);
}